/*******************************************************************************
*  file    : messagehandler.cpp
*  created : 15.08.2013
*  author  : 
*******************************************************************************/

#include "messagehandler.hpp"
#include "application.hpp"
#include <qlogger.hpp>
#include <cstdio>

namespace
{
QLogger* at = QLoggerEngine::getLogger("gsm");
QLogger* l  = QLoggerEngine::getLogger("core");
}

void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    Q_UNUSED(type)
    Q_UNUSED(context)
    if(msg.contains("AtChat:"))
        logInfo(at)<<msg;
    else
        logInfo(l)<<msg;
}

void installMyMessageHandler()
{
    QLoggerRollingFileAppender* c =
            new QLoggerRollingFileAppender(LevelAll,
                                           QString("%1/%2").arg(Application::instance()->logDir()).arg("modem_at.log"),
                                           "%d\t%m%n",
                                           1024*1024*5);
    at->addAppender(c);

    qInstallMessageHandler(myMessageOutput);
}
